<?php
/**
 * Created by PhpStorm.
 * User: 10838
 * Date: 2018/3/7
 * Time: 16:45
 */
namespace app\admin\controller;
use think\Controller;
use app\admin\model\MemberGroupModel;
use app\admin\model\Shop;
use app\admin\model\Terminal;
use app\admin\model\TransactionRecord;
class Wechat extends Controller{
    //自定义菜
    public function menu(){
        $assess_token = $this->get_access_token();
        //curl初始化
        $ch = curl_init();
        //请求地址
        $url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token={$assess_token}";
        curl_setopt($ch,CURLOPT_URL,$url);
        //捕获内容但不输出
        curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
        //模拟post发送
        curl_setopt($ch,CURLOPT_POST,1);
        //模拟数据
//        $date = '{
//             "button":[
//              {
//                   "name":"关于我们",
//                   "sub_button":[
//                   {
//                       "type":"view",
//                       "name":"公司介绍",
//                       "url":"http://xt.tianhzy.com"
//                    },
//                    {
//                       "type":"view",
//                       "name":"公司优势",
//                       "url":"http://xt.tianhzy.com"
//                    },
//                    {
//                       "type":"view",
//                       "name":"模式讲解",
//                     "url":"http://xt.tianhzy.com"
//                    },
//                    {
//                       "type":"view",
//                       "name":"装机教程",
//                       "url":"http://xt.tianhzy.com"
//                    },
//
//                    {
//                       "type":"view",
//                       "name":"APP下载",
//                       "url":"http://xt.tianhzy.com"
//                    }]
//               },
//                {
//                    "type":"view",
//                   "name":"明亚商城",
//                   "url":"http://xt.tianhzy.com"
//
//               },
//                {
//                    "type":"view",
//                   "name":"我的",
//                   "url":"https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxd66ecbf25782cee9&redirect_uri=http%3a%2f%2fxt.tianhzy.com%2findex%2forther%2fmy.html&response_type=code&scope=snsapi_userinfo&state=dianziguoqiao#wechat_redirect"
//               }
//               ]
//         }';
        curl_setopt($ch,CURLOPT_POSTFIELDS,$date);
        //执行
        $re = curl_exec($ch);
        //判`:断是否发送成功
        if($re == false){
            echo curl_error($ch);
        }else{
            echo $re;
        }
        //关闭
        curl_close($ch);
    }
    //获取assess_token
    public function get_access_token(){
        $appid = '';
        $secret = '';
        $get_url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={$appid}&secret={$secret}";
        $date = file_get_contents($get_url);
        $date = json_decode($date,true);
        return $date['access_token'];
    }



}
